#include "StdAfx.h"


#include "Frame.hxx"
#include "AppSetting.hxx"
#include "ChannelModel.hxx"
#include "ChannelView.hxx"
#include "ChannelFourBoxView.hxx"

ChannelModel::ChannelModel(TrackerModel* trackerModel)
{
	_trackerModel = trackerModel;
	_channelImage = 0;
	_channelIndex = -1;

	/*_frontPoints=0;
	_backPoints=0;
*/
	_frontPoints=(float *)malloc(sizeof(float)*10);
	_backPoints=(float *)malloc(sizeof(float)*10);
}


ChannelModel::~ChannelModel(void)
{
	if( _channelImage )
	{
		cvReleaseImage( &_channelImage );
		_channelImage = 0;
	}
}

void ChannelModel::initialize()
{
	//_channelImage = cvCreateImage( cvSize( RAW_FRAME_WIDTH, RAW_FRAME_HEIGHT ), IPL_DEPTH_8U, 3 );
	
	_channelImage = cvLoadImage( "D:/Temp/001.png" );

	/*_frontRect = __gHostInfo[ _channelIndex ].FrontBox;
	_backRect = __gHostInfo[ _channelIndex ].BackBox;*/

	_frontPoints=__gHostInfo[ _channelIndex ].frontPoints;
	_backPoints =__gHostInfo[ _channelIndex ].backPoints;

}

void ChannelModel::updateImage( IplImage* image )
{
	if( (image->width != RESIZED_FRAME_WIDTH ) || ( image->height != RESIZED_FRAME_HEIGHT ))
		cvResize( image, _channelImage );
	else
		cvCopy( image, _channelImage );

	_view->invalidate();

	///////////////////////Tian////////////////////////////////////////////
	_boxView->setValid(_channelIndex);

}

void ChannelModel::updateImageData( char* data )
{
	memcpy( _channelImage->imageData, data, _channelImage->imageSize );

	_view->invalidate();
///////////////////////Tian//////////////////////////////////////////////
	_boxView->setValid(_channelIndex);
	
}